﻿#include "mainui.h"

#include <QtWidgets>
#include <QtSql/QSqlDatabase>
#include <QtSql/QSqlError>
#include <QMessageBox>
#include <QFile>
QString inf[8];

int main(int argc, char *argv[])
{
    QApplication *a =new QApplication(argc, argv);
    Ui_mainui *u=new Ui_mainui;
    QFile file("test.txt");
    if(!file.open(QIODevice::WriteOnly))//以写的方式打开文件，如果文件不存在则创建，
        qDebug()<<file.errorString();
    QTextStream out(&file);

  /*
    QSqlDatabase db = QSqlDatabase::addDatabase("");
        db.setHostName("sh-cynosdbmysql-grp-ph2wxkca.sql.tencentcdb.com");
        db.setPort(27405);
        db.setDatabaseName("reg_lib");
        db.setUserName("iMakeit");
        db.setPassword("itmakeme@1024");
        bool ok = db.open();
        if (ok){
            qDebug()<<"ok";
        }
        else {
            qDebug()<<"error open database because"<<db.lastError().text();
        }*/
    QWidget* w=new QWidget;
    u->setupUi(w);
    w->show();
    QObject::connect(u->go,&QPushButton::clicked,a,[=,&file,&out](void){

        inf[0]=u->lineEdit_xingming->text();
        inf[1]=u->comboBox_jiban->currentText();
        inf[2]=u->comboBox_xingbei->currentText();
        inf[3]=u->lineEdit_qq->text();
        inf[4]=u->lineEdit_youxiang->text();
        inf[5]=u->lineEdit_dianhua->text();
        inf[6]=u->lineEdit_lishirongyu->text();
        inf[7]=u->comboBox_->currentText();
        u->lineEdit_dianhua->setText("");
        u->lineEdit_lishirongyu->setText("");
        u->lineEdit_qq->setText("");
        u->lineEdit_xingming->setText("");
        u->lineEdit_youxiang->setText("");
       // QByteArray buf = QByteArray::fromStdString(().toStdString());
       // file.write(buf);//写入文件，支持QByteArray和 char * 类型数据写入

        out << inf[0]+";"+inf[1]+";"+inf[2]+";"+inf[3]+";"+inf[4]+";"+inf[5]+";"+inf[6]+";"+inf[7]<<endl;
       // file.close();//关闭文件
        QMessageBox::information(NULL, "报名成功", "报名成功",
                                 QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes);

    });
    return a->exec();
}
